package cn.swust.designpatternlearningplatform.dao;

import cn.swust.designpatternlearningplatform.domain.entity.TopicIndicators;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface TopicIndicatorsDao {
    /**
     * 插入或者更新题目的难度系数
     *
     * @param topicIndicators
     * @author Tang
     * @date 2023/5/13 20:38
     **/
    @Insert("INSERT INTO topic_indicators(id, topic_id, degree_of_difficulty) " +
            "VALUE (#{indicator.id},#{indicator.topicId},#{indicator.degreeOfDifficulty}) " +
            "ON DUPLICATE KEY UPDATE topic_id             = VALUES(topic_id),\n" +
            "                        degree_of_difficulty = VALUES(degree_of_difficulty)")
    void insertOrUpdateTopicIndicatorsDifficulty(@Param("indicator") TopicIndicators topicIndicators);

    /**
     * 插入或者更新题目的区分度
     *
     * @param topicIndicators
     * @author Tang
     * @date 2023/5/13 20:38
     **/
    @Insert("INSERT INTO topic_indicators(id, topic_id, discrimination) " +
            "VALUE (#{indicator.id},#{indicator.topicId},#{indicator.discrimination}) " +
            "ON DUPLICATE KEY UPDATE topic_id       = VALUES(topic_id),\n" +
            "                        discrimination = VALUES(discrimination)")
    void insertOrUpdateTopicIndicatorsDiscrimination(@Param("indicator") TopicIndicators topicIndicators);

    /**
     * 根据题目id查询对应的题目指标参数
     * @param topicId
     * @return cn.swust.designpatternlearningplatform.domain.entity.TopicIndicators
     * @author Tang
     * @date 2023/5/16 16:48
    **/
    @Select("SELECT id, topic_id, degree_of_difficulty, discrimination " +
            "FROM topic_indicators " +
            "WHERE topic_id = #{topicId}")
    TopicIndicators selectByTopicId(@Param("topicId") Integer topicId);
}
